home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / FGMISC10.ZIP / GUI.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-26  |  7.1 KB  |  291 lines

  1. /****************************************************************************\
  2. *                                                                            *
  3. *  GUI.C -- generic menu code                                                *
  4. *                                                                            *
  5. \****************************************************************************/
  6.  
  7. #include "defs.h"
  8.  
  9. void main()
  10. {
  11.    init_graphics(22);
  12.    init_mouse();
  13.    do_menu();
  14. }
  15.  
  16. /****************************************************************************\
  17. *                                                                            *
  18. *  do_menu -- main menu control code                                         *
  19. *                                                                            *
  20. \****************************************************************************/
  21.  
  22. void do_menu()
  23. {
  24.    unsigned char key,aux;
  25.    int mousex, mousey, count;
  26.    register int i;
  27.  
  28.    xlimit = 319;
  29.    ylimit = 239;
  30.    redraw = TRUE;
  31.    main_option = 0; /* this is a global value */
  32.  
  33.    /* draw the screen on the hidden page and copy it to the visual page */
  34.  
  35.    draw_screen();
  36.  
  37.    /* begin the main program loop */
  38.  
  39.    for(;;)
  40.    {
  41.       fg_mousevis(ON);
  42.       fg_waitfor(2);
  43.  
  44.       /* intercept a keystroke */
  45.  
  46.       fg_intkey(&key,&aux);
  47.       if (key == ESC)
  48.       {
  49.          exit_program();
  50.          continue;
  51.       }
  52.       else if (aux == RIGHT_ARROW)
  53.       {
  54.          main_option++;
  55.          if (main_option == ITEMS)
  56.             main_option = 0;
  57.       }
  58.       else if (aux == LEFT_ARROW)
  59.       {
  60.          main_option--;
  61.          if (main_option < 0)
  62.             main_option = ITEMS - 1;
  63.       }
  64.  
  65.       /* display menu according to keystroke pressed */
  66.  
  67.       if (key+aux > 0)
  68.       {
  69.          fg_mousevis(OFF);
  70.  
  71.          fg_restore(0,319,MENU_TOP,MENU_BOTTOM);
  72.          horizontal_menu(main_menu,4,main_option);
  73.          if (main_option == ESC)
  74.          {
  75.             exit_program();
  76.             main_option = 0;
  77.          }
  78.          fg_mousevis(OFF);
  79.          fg_restore(0,xlimit,MENU_TOP,ylimit);
  80.          horizontal_menu(main_menu,-4,main_option);
  81.          fg_mousevis(ON);
  82.       }
  83.  
  84.       /* intercept a mouse click */
  85.  
  86.       if (mouse)
  87.       {
  88.          fg_mousebut(1,&count,&mousex,&mousey);
  89.          if (count > 0 && BETWEEN(mousey,MENU_TOP,MENU_BOTTOM))
  90.          {
  91.             for (i = 0; i < ITEMS; i++)
  92.             {
  93.                if (BETWEEN(mousex, mouse_limits[i], mouse_limits[i+1]))
  94.                {
  95.                   fg_restore(0,319,MENU_TOP,MENU_BOTTOM);
  96.                   if (horizontal_menu(main_menu,4,i) == ESC)
  97.                      exit_program();
  98.                   fg_mousevis(OFF);
  99.                   fg_restore(0,xlimit,MENU_TOP,ylimit);
  100.                   horizontal_menu(main_menu,-4,main_option);
  101.                   fg_mousevis(ON);
  102.                   break;
  103.                }
  104.             }
  105.          }
  106.       }
  107.    }
  108. }
  109.  
  110. /****************************************************************************\
  111. *                                                                            *
  112. *  draw_screen -- draw the main menu screen on the hidden page               *
  113. *                                                                            *
  114. \****************************************************************************/
  115.  
  116. void draw_screen()
  117. {
  118.    static char *string[] =
  119.    {
  120.       "Bunch of menu code",
  121.       "Copyright 1992-1993 Ted Gruber Software"
  122.    };
  123.  
  124.    /* erase the hidden page */
  125.  
  126.    fg_mousevis(0);
  127.    fg_setpage(HIDDEN);
  128.    fg_erase();
  129.  
  130.    /* draw some rectangles */
  131.  
  132.    fg_setcolor(white);
  133.    fg_rect(0,xlimit,0,ylimit);
  134.    fg_setcolor(red);
  135.    fg_rect(0,xlimit,0,12);
  136.    fg_setcolor(blue);
  137.    fg_rect(0,xlimit,25,ylimit);
  138.    fg_setcolor(black);
  139.    fg_rect(0,xlimit,12,12);
  140.    fg_rect(0,xlimit,24,24);
  141.  
  142.    /* main menu title */
  143.  
  144.    fg_setcolor(black);
  145.    center_bstring(string[0],0,317,7);
  146.    fg_setcolor(white);
  147.    center_bstring(string[0],0,319,8);
  148.  
  149.    /* copyright notice at bottom of screen */
  150.  
  151.    fg_setcolor(black);
  152.    center_bstring(string[1],0,317,236);
  153.    fg_setcolor(white);
  154.    center_bstring(string[1],0,319,237);
  155.  
  156.    fg_setpage(VISUAL);
  157.    fg_restore(0,xlimit,0,ylimit);
  158.    horizontal_menu(main_menu,-4,main_option);
  159. }
  160.  
  161. char infile[13];
  162. char outfile[13];
  163. char otherfile[13];
  164.  
  165. /****************************************************************************\
  166. *                                                                            *
  167. *  load_files -- enter strings for file names                                *
  168. *                                                                            *
  169. \****************************************************************************/
  170.  
  171. load_files()
  172. {
  173.    register int i,j;
  174.    int y;
  175.    int current;
  176.    char string[13];
  177.  
  178.    static char *string1[] = {
  179.       "      Enter file names",
  180.       " ",
  181.       "Input file:",
  182.       "Output file:",
  183.       "Other file:",
  184.       " ",
  185.       "      Press F10 to start"
  186.    };
  187.  
  188.    static char *string2[] = {infile,outfile,otherfile};
  189.    static int y1[] = {90,100,110};
  190.  
  191.    /* put your own stuff in here */
  192.  
  193.    strcpy(infile,"infile.dat");
  194.    strcpy(outfile,"outfile.dat");
  195.    strcpy(otherfile,"other.dat");
  196.  
  197.    fg_mousevis(0);
  198.    fg_setcolor(blue);
  199.    fg_rect(0,319,25,199);
  200.  
  201.    fg_setcolor(black);
  202.    fg_rect(0,319,24,24);
  203.  
  204.    fg_setcolor(white);
  205.    fg_rect(32,288,55,145);
  206.    fg_setcolor(black);
  207.    fg_box(32,288,55,145);
  208.  
  209.    y = 70;
  210.    for (i = 0; i < 7; i++)
  211.    {
  212.       put_bstring(string1[i],60,y);
  213.       y+= 10;
  214.    }
  215.  
  216.    for (i = 0; i < 3; i++)
  217.    {
  218.       put_bstring(string2[i],180,y1[i]);
  219.    }
  220.  
  221.    current = 0;
  222.  
  223.    for(;;)
  224.    {
  225.       strcpy(string,string2[current]);
  226.       fg_setcolor(blue);
  227.       j = get_field(string,180,y1[current],12,0,0);
  228.  
  229.       if (j == ESC)
  230.       {
  231.          fg_setcolor(blue);
  232.          fg_rect(0,319,25,199);
  233.          redraw = TRUE;
  234.          return(OK);
  235.       }
  236.       if (j == UP_ARROW || j == DOWN_ARROW || j == ENTER)
  237.       {
  238.          strcpy(string2[current],string);
  239.          fg_setcolor(white);
  240.          fg_rect(180,287,y1[current]-9,y1[current]);
  241.          fg_setcolor(black);
  242.          put_bstring(string2[current],180,y1[current]);
  243.       }
  244.  
  245.       /* next field */
  246.  
  247.       if (j == DOWN_ARROW)
  248.       {
  249.          current++;
  250.          if (current > 2)
  251.             current = 0;
  252.       }
  253.  
  254.       /* previous field */
  255.  
  256.       else if (j == UP_ARROW)
  257.       {
  258.          current--;
  259.          if (current < 0)
  260.             current = 2;
  261.       }
  262.       else if (j == F10)
  263.          break;
  264.    }
  265.  
  266.    /* check and see if the file exists */
  267.  
  268.    if (!file_exists(infile))
  269.    {
  270.       fg_setcolor(white);
  271.       fg_rect(33,287,56,144);
  272.       fg_setcolor(black);
  273.       center_bstring("file not found",33,287,100);
  274.       fg_waitkey();
  275.       fg_setcolor(blue);
  276.       fg_rect(0,319,25,199);
  277.       redraw = TRUE;
  278.       return(OK);
  279.    }
  280.  
  281.    /* clear the screen and return */
  282.  
  283.    fg_setcolor(blue);
  284.    fg_rect(0,319,25,239);
  285.    redraw = TRUE;
  286.    return(OK);
  287. }
  288.  
  289.  
  290.  
  291.